﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using wUniAppPCL.IO;
using wUniAppPCL.MVVM;

namespace wUniAppPCL
{
  public class PatientsViewModel : BaseCollectionViewModel<Person>
  {

    public static void GenerateTestData(ref IList<Person> Items, int count = 100000)
    {
      Random rnd = new Random();
      Items.Clear();
      for (int i = 1; i < count; i++)
      {
        var age = rnd.Next(1, 100);
        var weight = rnd.Next(40, 120);
        var height = rnd.Next(150, 220);
        string si = i.ToString();
        Items.Add(new Person() { FirstName = "FirstName" + si, LastName = "LastName" + si, Age = age, Height = height, Weight = weight, Id = i });
      }
    }


    internal void Insert(Person person)
    {
      Items.Insert(0, person);
      selectedItem = person;
    }
    internal void Delete(Person person)
    {
      Items.Remove(person);
    }

    // Taks1 - B  vypocita priemernu vysku vsetkych co maju vahu nad prier
    public double GetAvgHeight()
    {
      double avgWeight = Items.Average(w => w.Weight);
      var res = Items.Where(c => c.Weight > avgWeight).Average(x => x.Height);
      return res;
    }
  }
}
